﻿using ProjectManageSystemApi.Utilities;
using System.ComponentModel;

namespace ProjectManageSystemApi.Models
{
    public class ApiResult
    {
        public int Code { get; set; }
        public string Message { get; set; }
    }
    public class ApiResult<T> : ApiResult
    {
        public T Datas { get; set; }
    }

    static class ApiResultStatus
    {
        public static ApiResult Fail()
        {
            return new ApiResult
            {
                Code = (int)ApiResultCodes.OPERATION_FAILED,
                Message = ApiResultCodes.OPERATION_FAILED.GetDescription()
            };
        }
        public static ApiResult Fail(ApiResultCodes code)
        {
            return new ApiResult
            {
                Code = (int)code,
                Message = code.GetDescription()
            };
        }
        public static ApiResult Fail(ApiResultCodes code, string msg)
        {
            return new ApiResult
            {
                Code = (int)code,
                Message = msg
            };
        }
        public static ApiResult Success()
        {
            return new ApiResult
            {
                Code = (int)ApiResultCodes.SUCCESS,
                Message = ApiResultCodes.SUCCESS.GetDescription()
            };
        }
        public static ApiResult Success<T>(T datas)
        {
            return new ApiResult<T>
            {
                Code = (int)ApiResultCodes.SUCCESS,
                Message = ApiResultCodes.SUCCESS.GetDescription(),
                Datas = datas
            };
        }
        public static ApiResult Create(bool operation, ApiResultCodes failCode)
        {
            return operation ? Success() : Fail(failCode);
        }
        public static ApiResult Create<T>(bool operation, ApiResultCodes failCode, T datas)
        {
            return operation ? Success(datas) : Fail(failCode);
        }
    }
    public enum ApiResultCodes
    {
        [Description("操作成功")]
        SUCCESS = 20000,

        [Description("参数错误")]
        PARAMS_FAILED = 50001,

        [Description("数据已存在")]
        DATA_EXIST = 50002,

        [Description("操作失败")]
        OPERATION_FAILED = 50003,

        [Description("数据不存在")]
        DATA_NOT_EXIST = 50004,

        [Description("存在关联数据,不可删除")]
        CANNOT_DELETE = 50005,

        [Description("账号不存在")]
        ACCOUNT_NOT_EXIST = 50006,

        [Description("账号名已存在")]
        ACCOUNT_NAME_EXIST = 50007,

        [Description("密码错误")]
        PASSWORD_FAILED = 50009,

        [Description("验证码错误")]
        VERIFICODE_FAILED = 50010,

        [Description("工程名称已经存在")]
        PROJECT_NAME_EXIST = 50011,

        [Description("工程已经完成，不允许修改")]
        PROJECT_FINISH = 50012,

        [Description("项目名称已经存在")]
        PROJECT_ITEM_NAME_EXIST = 50013,

        [Description("项目报销已经被处理，不允许修改")]
        PROJECT_COST_DEAL_WITH = 50014,

        [Description("项目报销类型名称已经存在")]
        PROJECT_COST_TYPE_NAME_EXIST = 50015,

        [Description("供应商名称已经存在")]
        SUPPLIER_NAME_EXIST = 50016,

        [Description("供应商原料名称已经存在")]
        SUPPLIER_GOODS_NAME_EXIST = 50017,

        [Description("不允许登录该平台，请联系管理员增加权限")]
        NOT_ALLOWED_LOGIN_PLATFORM = 50018,

        [Description("工种类型名称已经存在")]
        WORKER_TYPE_INFO_NAME_EXIST = 50019,

        [Description("工种类型 Id 不存在")]
        WORKER_TYPE_INFO_ID_NOT_EXIST = 50020,

        [Description("excel导入，文件类型未知")]
        EXCEL_UPLOAD_FILE_TYPE_UNKNOWS = 50021,

        [Description("工程名称不存在")]
        PROJECT_NAME_NOT_EXIST = 50022,

        [Description("单号已经存在")]
        BILL_NO_EXIST = 50023,

        [Description("App名称和内部版本号已经存在")]
        APPNAME_INSIDENO_EXIST = 50024,

        [Description("服务器异常")]
        SERVER_ERROR = 50000,

    }
}
